<template>
  <div>
    <template v-if="widget.type == 'input'">
      <finput :setting="widget" :models="models"></finput>
    </template>
    <template v-if="widget.type == 'select'">
      <Fselect :setting="widget" :models="models"></Fselect>
    </template>
    <template v-if="widget.type == 'date'">
      <Fdate :setting="widget" :models="models"></Fdate>
    </template>
    <template v-if="widget.type == 'number'">
      <Fnumber
        @totalNumber="totalNumber"
        :setting="widget"
        :models="models"
      ></Fnumber>
    </template>
    <template v-if="widget.type == 'radio'">
      <Fradio :setting="widget" :models="models"></Fradio>
    </template>
    <template v-if="widget.type == 'checkbox'">
      <Fcheckbox :setting="widget" :models="models"></Fcheckbox>
    </template>
    <template v-if="widget.type == 'rate'">
      <Frate :setting="widget" :models="models"></Frate>
    </template>
    <template v-if="widget.type == 'switch'">
      <Fswitch :setting="widget" :models="models"></Fswitch>
    </template>
    <template v-if="widget.type == 'slider'">
      <Fslider :setting="widget" :models="models"></Fslider>
    </template>
    <template v-if="widget.type == 'text'">
      {{ widget.options.defaultValue }}
    </template>
    <template v-if="widget.type == 'imgupload'">
      <FuploadImg :setting="widget" :models="models"></FuploadImg>
    </template>
    <template v-if="widget.type == 'fileupload'">
      <FuploadFile :setting="widget" :models="models"></FuploadFile>
    </template>
 
  </div>
</template>

<script>
  import {
    Finput,
    Fdate,
    Fselect,
    Fnumber,
    Fradio,
    Fcheckbox,
    Frate,
    Fswitch,
    Fslider,
    FuploadImg,
    FuploadFile,
    Ftable,
  } from './index'

  import { GetDictByPid } from '@/api/dictionary/api'

  export default {
    // eslint-disable-next-line vue/require-prop-types
    props: ['widget', 'models', 'tablename', 'formdata'],
    components: {
      Finput,
      Fdate,
      Fselect,
      Fnumber,
      Fradio,
      Fcheckbox,
      Frate,
      Fswitch,
      Fslider,
      FuploadImg,
      FuploadFile,
      Ftable,
    },
    created() {
      if (this.widget.options.remote == true) {
        GetDictByPid({ id: this.widget.options.remoteFunc }).then((res) => {
          this.widget.options.remoteOptions = res.content.map((item) => {
            return {
              value: item.id,
              label: item.name,
            }
          })
        })
      }
    },
    methods: {
      totalNumber() {
        this.$emit('handleTotal')
      },
    },
  }
</script>
